#include <bits/stdc++.h>
using namespace std;
int n, m, k, edge[11000], num[110];
bool e[10010][10010];

//不同盘  有多个相同的图案

int check2() {
  for (int i = 1; i <= m; ++i)
    for (int j = 1; j <= m; ++j)
      if (i == j)
        continue;
      else if (num[i] != num[j] && e[num[i]][num[j]] == 0)
        e[num[i]][num[j]] = 1;
      else
        return 0;
  return 1;
}

//不同盘 没有相同图案
int check0(int sum) {
  for (int i = 1; i <= m; ++i)
    sum -= edge[num[i]];
  for (int i = 1; i <= m; ++i)
    edge[num[i]]++;
  return (sum == 0);
}

int main() {
  cin >> n >> m >> k;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j)
      cin >> num[j];
    if (!check2() || !check0(i - 1)) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}